package ${package.Controller};

import com.mybatisplus.common.model.result.ResultBean;
import com.mybatisplus.common.model.param.ParamBean;
import org.springframework.web.bind.annotation.*;
import com.mybatisplus.common.page.PageVo;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import  ${package.Service}.${table.serviceName};
import  ${package.Entity}.${table.entityName};
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
* <p>
* ${table.comment!} 前端控制器
* </p>
*
* @author ${author}
* @since ${date}
*/
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@Slf4j
@Api(tags = "${table.name}_CRUD接口")
@RequestMapping("/${table.name}")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    private final Logger logger = LoggerFactory.getLogger(${table.controllerName}.class);

    @Autowired
    private ${table.serviceName} ${table.name}Service;

    @ApiOperation(value = "获取${table.name}列表",notes="")
    @GetMapping("/list")
    public List<${table.entityName}> ${table.name}List() throws Exception {
        List<${table.entityName}> ${table.name}List = ${table.name}Service.list();
        return ${table.name}List;
    }

    @ApiOperation(value = "修改${table.name}",notes="根据id修改${table.name}")
    @ApiImplicitParam(name = "${table.name}", value = "${table.name}实体", required = true, dataType = "${table.name}")
    @PutMapping("/update")
    public ResultBean<Boolean> ${table.name}Update(@RequestBody  ${table.entityName} ${table.name}) throws Exception {
        Boolean flag = ${table.name}Service.updateById(${table.name});
        return ResultBean.createSuccess();
    }

    @ApiOperation(value = "删除${table.name}",notes="根据id删除${table.name}")
    @ApiImplicitParam(name = "id", value = "${table.name}id", required = true, dataType = "<#list table.fields as field><#if field.keyFlag == true>${field.columnType?lower_case?cap_first}</#if></#list>")
    @DeleteMapping("/delete/{id}")
    public ResultBean<Boolean> ${table.name}Delete(@PathVariable <#list table.fields as field><#if field.keyFlag == true>${field.columnType?lower_case?cap_first}</#if></#list> id) throws Exception {
        Boolean flag = ${table.name}Service.removeById(id);
        return ResultBean.createSuccess();
    }

    @ApiOperation(value = "添加${table.name}",notes="新增一条${table.name}")
    @ApiImplicitParam(name = "${table.name}", value = "${table.name}实体", required = true, dataType = "${table.name}")
    @PostMapping("/insert")
    public ResultBean<Boolean> ${table.name}Insert(@RequestBody ${table.entityName} ${table.name}) throws Exception {
        Boolean flag = ${table.name}Service.save(${table.name});
        return ResultBean.createSuccess();
    }

    @ApiOperation(value = "分页查询${table.name}",notes="通过分页条件和查询条件查询${table.name}")
    @ApiImplicitParam(name = "${table.name}", value = "${table.name}实体", required = true, dataType = "paramBean")
    @PostMapping("/page")
    public ResultBean<PageVo> pageList(@RequestBody ParamBean<${table.entityName}> paramBean) throws Exception {
        ResultBean resultBean = ${table.name}Service.pageList(paramBean);
        return resultBean;
    }
}
</#if>